home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / include / rpc / clnt.h < prev    next >
C/C++ Source or Header  |  1991-03-23  |  9KB  |  345 lines

  1. /* @(#)clnt.h    1.1 87/11/04 3.9 RPCSRC */
  2. /*
  3.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  4.  * unrestricted use provided that this legend is included on all tape
  5.  * media and as a part of the software program in whole or part.  Users
  6.  * may copy or modify Sun RPC without charge, but are not authorized
  7.  * to license or distribute it to anyone else except as part of a product or
  8.  * program developed by the user.
  9.  * 
  10.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  11.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  13.  * 
  14.  * Sun RPC is provided with no support and without any obligation on the
  15.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  16.  * modification or enhancement.
  17.  * 
  18.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  19.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  20.  * OR ANY PART THEREOF.
  21.  * 
  22.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  23.  * or profits or other special, indirect and consequential damages, even if
  24.  * Sun has been advised of the possibility of such damages.
  25.  * 
  26.  * Sun Microsystems, Inc.
  27.  * 2550 Garcia Avenue
  28.  * Mountain View, California  94043
  29.  */
  30. /*    @(#)clnt.h 1.30 87/07/14 SMI      */
  31.  
  32. /*
  33.  * clnt.h - Client side remote procedure call interface.
  34.  *
  35.  * Copyright (C) 1984, Sun Microsystems, Inc.
  36.  */
  37.  
  38. #ifndef _CLNT_
  39. #define _CLNT_
  40.  
  41. /*
  42.  * Rpc calls return an enum clnt_stat.  This should be looked at more,
  43.  * since each implementation is required to live with this (implementation
  44.  * independent) list of errors.
  45.  */
  46. enum clnt_stat {
  47.     RPC_SUCCESS=0,            /* call succeeded */
  48.     /*
  49.      * local errors
  50.      */
  51.     RPC_CANTENCODEARGS=1,        /* can't encode arguments */
  52.     RPC_CANTDECODERES=2,        /* can't decode results */
  53.     RPC_CANTSEND=3,            /* failure in sending call */
  54.     RPC_CANTRECV=4,            /* failure in receiving result */
  55.     RPC_TIMEDOUT=5,            /* call timed out */
  56.     /*
  57.      * remote errors
  58.      */
  59.     RPC_VERSMISMATCH=6,        /* rpc versions not compatible */
  60.     RPC_AUTHERROR=7,        /* authentication error */
  61.     RPC_PROGUNAVAIL=8,        /* program not available */
  62.     RPC_PROGVERSMISMATCH=9,        /* program version mismatched */
  63.     RPC_PROCUNAVAIL=10,        /* procedure unavailable */
  64.     RPC_CANTDECODEARGS=11,        /* decode arguments error */
  65.     RPC_SYSTEMERROR=12,        /* generic "other problem" */
  66.  
  67.     /*
  68.      * callrpc & clnt_create errors
  69.      */
  70.     RPC_UNKNOWNHOST=13,        /* unknown host name */
  71.     RPC_UNKNOWNPROTO=17,        /* unkown protocol */
  72.  
  73.     /*
  74.      * _ create errors
  75.      */
  76.     RPC_PMAPFAILURE=14,        /* the pmapper failed in its call */
  77.     RPC_PROGNOTREGISTERED=15,    /* remote program is not registered */
  78.     /*
  79.      * unspecified error
  80.      */
  81.     RPC_FAILED=16
  82. };
  83.  
  84.  
  85. /*
  86.  * Error info.
  87.  */
  88. struct rpc_err {
  89.     enum clnt_stat re_status;
  90.     union {
  91.         int RE_errno;        /* realated system error */
  92.         enum auth_stat RE_why;    /* why the auth error occurred */
  93.         struct {
  94.             u_long low;    /* lowest verion supported */
  95.             u_long high;    /* highest verion supported */
  96.         } RE_vers;
  97.         struct {        /* maybe meaningful if RPC_FAILED */
  98.             long s1;
  99.             long s2;
  100.         } RE_lb;        /* life boot & debugging only */
  101.     } ru;
  102. #define    re_errno    ru.RE_errno
  103. #define    re_why        ru.RE_why
  104. #define    re_vers        ru.RE_vers
  105. #define    re_lb        ru.RE_lb
  106. };
  107.  
  108.  
  109. /*
  110.  * Client rpc handle.
  111.  * Created by individual implementations, see e.g. rpc_udp.c.
  112.  * Client is responsible for initializing auth, see e.g. auth_none.c.
  113.  */
  114. typedef struct {
  115.     AUTH    *cl_auth;            /* authenticator */
  116.     struct clnt_ops {
  117.         enum clnt_stat    (*cl_call)();    /* call remote procedure */
  118.         void        (*cl_abort)();    /* abort a call */
  119.         void        (*cl_geterr)();    /* get specific error code */
  120.         bool_t        (*cl_freeres)(); /* frees results */
  121.         void        (*cl_destroy)();/* destroy this structure */
  122.         bool_t          (*cl_control)();/* the ioctl() of rpc */
  123.     } *cl_ops;
  124.     caddr_t            cl_private;    /* private stuff */
  125. } CLIENT;
  126.  
  127.  
  128. /*
  129.  * client side rpc interface ops
  130.  *
  131.  * Parameter types are:
  132.  *
  133.  */
  134.  
  135. /*
  136.  * enum clnt_stat
  137.  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  138.  *     CLIENT *rh;
  139.  *    u_long proc;
  140.  *    xdrproc_t xargs;
  141.  *    caddr_t argsp;
  142.  *    xdrproc_t xres;
  143.  *    caddr_t resp;
  144.  *    struct timeval timeout;
  145.  */
  146. #define    CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)    \
  147.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  148. #define    clnt_call(rh, proc, xargs, argsp, xres, resp, secs)    \
  149.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  150.  
  151. /*
  152.  * void
  153.  * CLNT_ABORT(rh);
  154.  *     CLIENT *rh;
  155.  */
  156. #define    CLNT_ABORT(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  157. #define    clnt_abort(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  158.  
  159. /*
  160.  * struct rpc_err
  161.  * CLNT_GETERR(rh);
  162.  *     CLIENT *rh;
  163.  */
  164. #define    CLNT_GETERR(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  165. #define    clnt_geterr(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  166.  
  167.  
  168. /*
  169.  * bool_t
  170.  * CLNT_FREERES(rh, xres, resp);
  171.  *     CLIENT *rh;
  172.  *    xdrproc_t xres;
  173.  *    caddr_t resp;
  174.  */
  175. #define    CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  176. #define    clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  177.  
  178. /*
  179.  * bool_t
  180.  * CLNT_CONTROL(cl, request, info)
  181.  *      CLIENT *cl;
  182.  *      u_int request;
  183.  *      char *info;
  184.  */
  185. #define    CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  186. #define    clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  187.  
  188. /*
  189.  * control operations that apply to both udp and tcp transports
  190.  */
  191. #define CLSET_TIMEOUT       1   /* set timeout (timeval) */
  192. #define CLGET_TIMEOUT       2   /* get timeout (timeval) */
  193. #define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
  194. /*
  195.  * udp only control operations
  196.  */
  197. #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
  198. #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
  199. #define CLSET_RETRY_COUNT   6   /* set retry count (int)       */
  200. #define CLGET_RETRY_COUNT   7   /* get retry count (int)       */
  201. #define CLSET_RETRY_DELAY   8   /* set retry delay in secs(int)*/
  202. #define CLGET_RETRY_DELAY   9   /* get retry delay in secs(int)*/
  203.  
  204. /*
  205.  * udp sockets only: allow I/O retries if an EIO error is detected.
  206.  * These values can be altered with a clnt_control call.
  207.  * No support was added on the server side.
  208.  */
  209. #define RETRYCOUNTDFL 0         /* max retries.(-1 == infinity)*/
  210. #define RETRYDELAYDFL 60        /* delay (secs) between retries*/
  211.  
  212. /*
  213.  * void
  214.  * CLNT_DESTROY(rh);
  215.  *     CLIENT *rh;
  216.  */
  217. #define    CLNT_DESTROY(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  218. #define    clnt_destroy(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  219.  
  220.  
  221. /*
  222.  * RPCTEST is a test program which is accessable on every rpc
  223.  * transport/port.  It is used for testing, performance evaluation,
  224.  * and network administration.
  225.  */
  226.  
  227. #define RPCTEST_PROGRAM        ((u_long)1)
  228. #define RPCTEST_VERSION        ((u_long)1)
  229. #define RPCTEST_NULL_PROC    ((u_long)2)
  230. #define RPCTEST_NULL_BATCH_PROC    ((u_long)3)
  231.  
  232. /*
  233.  * By convention, procedure 0 takes null arguments and returns them
  234.  */
  235.  
  236. #define NULLPROC ((u_long)0)
  237.  
  238. /*
  239.  * Below are the client handle creation routines for the various
  240.  * implementations of client side rpc.  They can return NULL if a 
  241.  * creation failure occurs.
  242.  */
  243.  
  244. /*
  245.  * Memory based rpc (for speed check and testing)
  246.  * CLIENT *
  247.  * clntraw_create(prog, vers)
  248.  *    u_long prog;
  249.  *    u_long vers;
  250.  */
  251. extern CLIENT *clntraw_create();
  252.  
  253.  
  254. /*
  255.  * Generic client creation routine. Supported protocols are "udp" and "tcp"
  256.  */
  257. extern CLIENT *
  258. clnt_create(/*host, prog, vers, prot*/); /*
  259.     char *host;     -- hostname
  260.     u_long prog;    -- program number
  261.     u_long vers;    -- version number
  262.     char *prot;    -- protocol
  263. */
  264.  
  265.     
  266.     
  267.  
  268. /*
  269.  * TCP based rpc
  270.  * CLIENT *
  271.  * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
  272.  *    struct sockaddr_in *raddr;
  273.  *    u_long prog;
  274.  *    u_long version;
  275.  *    register int *sockp;
  276.  *    u_int sendsz;
  277.  *    u_int recvsz;
  278.  */
  279. extern CLIENT *clnttcp_create();
  280.  
  281. /*
  282.  * UDP based rpc.
  283.  * CLIENT *
  284.  * clntudp_create(raddr, program, version, wait, sockp)
  285.  *    struct sockaddr_in *raddr;
  286.  *    u_long program;
  287.  *    u_long version;
  288.  *    struct timeval wait;
  289.  *    int *sockp;
  290.  *
  291.  * Same as above, but you specify max packet sizes.
  292.  * CLIENT *
  293.  * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
  294.  *    struct sockaddr_in *raddr;
  295.  *    u_long program;
  296.  *    u_long version;
  297.  *    struct timeval wait;
  298.  *    int *sockp;
  299.  *    u_int sendsz;
  300.  *    u_int recvsz;
  301.  */
  302. extern CLIENT *clntudp_create();
  303. extern CLIENT *clntudp_bufcreate();
  304.  
  305. /*
  306.  * Print why creation failed
  307.  */
  308. void clnt_pcreateerror(/* char *msg */);    /* stderr */
  309. char *clnt_spcreateerror(/* char *msg */);    /* string */
  310.  
  311. /*
  312.  * Like clnt_perror(), but is more verbose in its output
  313.  */ 
  314. void clnt_perrno(/* enum clnt_stat num */);    /* stderr */
  315.  
  316. /*
  317.  * Print an English error message, given the client error code
  318.  */
  319. void clnt_perror(/* CLIENT *clnt, char *msg */);     /* stderr */
  320. char *clnt_sperror(/* CLIENT *clnt, char *msg */);    /* string */
  321.  
  322. /* 
  323.  * If a creation fails, the following allows the user to figure out why.
  324.  */
  325. struct rpc_createerr {
  326.     enum clnt_stat cf_stat;
  327.     struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  328. };
  329.  
  330. extern struct rpc_createerr rpc_createerr;
  331.  
  332.  
  333.  
  334. /*
  335.  * Copy error message to buffer.
  336.  */
  337. char *clnt_sperrno(/* enum clnt_stat num */);    /* string */
  338.  
  339.  
  340.  
  341. #define UDPMSGSIZE    8800    /* rpc imposed limit on udp msg size */
  342. #define RPCSMALLMSGSIZE    400    /* a more reasonable packet size */
  343.  
  344. #endif /*!_CLNT_*/
  345.